package com.shizhanzhe.qdd.forward.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.shizhanzhe.qdd.R;
import com.shizhanzhe.qdd.forward.bean.Class;
import com.shizhanzhe.qdd.forward.bean.ShareDetail;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zz9527 on 2019/4/15.
 */
public class ManagerAdapter extends RecyclerView.Adapter<ManagerAdapter.ViewHolder> {
    private Context mContext;
    private List<Class> mData = new ArrayList<>();
    private boolean isshow=false;
    public ManagerAdapter(Context context) {
        mContext = context;
    }

    public void updateData(List<Class> dataSet) {
        if (dataSet != null && !dataSet.isEmpty()) {
            mData=dataSet;
            notifyDataSetChanged();
        }
    }
    public void show(){
        isshow=true;
        notifyDataSetChanged();
    }
    public void hide(){
        isshow=false;
        notifyDataSetChanged();
    }

    public void remove(int position) {

        mData.remove(position);
        notifyDataSetChanged();

    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_manager, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {

        Class aClass = mData.get(position);
        holder.tv.setText(aClass.getName());
        if (isshow){
            holder.delete.setVisibility(View.VISIBLE);
        }else {
            holder.delete.setVisibility(View.INVISIBLE);
        }
        if (position == 0) {
            holder.delete.setVisibility(View.INVISIBLE);
        }
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mItemClickListener.onItemDeleteClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv)
        TextView tv;
        @BindView(R.id.delete)
        ImageView delete;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private ManagerAdapter.ItemClickListener mItemClickListener;

    public interface ItemClickListener {
        public void onItemDeleteClick(int position);
    }

    public void setOnItemClickListener(ManagerAdapter.ItemClickListener itemClickListener) {
        this.mItemClickListener = itemClickListener;

    }
}
